﻿@using System.Configuration
@using LY.Entity
@using LY.Interface
@using LY.Business.ServiceImpl
@model LY.Entity.Entities.T_Project_EX
@{
    ViewBag.Title = "ConfirmInvest";
    Layout = null;
    //Model.AnnualisedRates *= 100;
    //Model.AddAnnualisedRates *= 100;
    IClaimsService claim = new ClaimsService();
    string sftAddress = ConfigurationManager.AppSettings["SftAddress"];
    string merchantNo = ConfigurationManager.AppSettings["merchantNo"];
    string submitBidNo = "quanju" + DateTime.Now.ToString("yyMMddHHmmss") + new Random().Next(0, 99999);
    U_Member member = Session["CurrentUser"] as U_Member;
    string backAddress = ConfigurationManager.AppSettings["BackAddress"];
    var avaAmounts = Math.Round((decimal)Model.TotalLoan - claim.GetAmountsByPid(Model.ID.ToString()), 0);//剩余的投标金额
    var discount = Math.Round((decimal)(ViewBag.myScore * 0.01), 2);
}

<style>
    .partline {
        width: 99%;
        height: 40px;
        border: none;
        border-bottom: 2px solid #EC303F;
        padding: 10px 0 0 10px;
    }

        .partline b {
            color: #EC303F;
            font-size: 20px;
        }

    .pcontent {
        padding: 10px 0 0 20px;
    }

    table tr {
        border-bottom: 1px solid #808080;
        line-height: 50px;
    }

        table tr td {
            width: 260px;
            font-size: 16px;
        }

    .btn-blue {
        background-color: #EC303F;
        color: white;
        border: none;
        font-size: 14px;
        padding: 8px;
        width: 80px;
        cursor: pointer;
        border-radius: 10px;
    }
</style>
<script src="~/Scripts/jquery-1.9.1.min.js"></script>
<script src="~/Scripts/lhgdialog/lhgdialog.js?skin=idialog"></script>

<div class="container">
    <div class="partline">
        <b>@Model.ProjectName</b>
    </div>
    <div class="pcontent">
        <input type="hidden" id="projectId" value="@Model.ID"/>
        <table>
            <tr>
                <td>项目期限：<b style="color: #EC303F;">@Model.ProjectDurationStr</b>
                </td>
                <td>预期年化收益：<b style="color: #EC303F;">@((Model.AnnualisedRates + Model.AddAnnualisedRates) * 100) %</b>
                </td>
                <td>还款方式：每月付息，到期还本
                </td>
            </tr>
            <tr>
                <td>投资金额：<b style="color: #EC303F;">@ViewBag.Amount</b> 元
                </td>
                <td>预期收益额：<b style="color: #EC303F;">
                              @if (Model.DurationMonthOrDay == 2)
                              {
                                  @(string.Format("{0:F2}", Convert.ToDouble(ViewBag.Amount) * (Model.AnnualisedRates + Model.AddAnnualisedRates) / 365 * Model.ProjectDuration)) 

                              }
                              else
                              {
                                  @(string.Format("{0:F2}", Convert.ToDouble(ViewBag.Amount) * (Model.AnnualisedRates + Model.AddAnnualisedRates) / 12 * Model.ProjectDuration)) 
                              }
                    元
                          </b>
                </td>
                <td>可获积分：<b style="color: #EC303F;">@(Convert.ToInt32(ViewBag.Amount) * 0.2) </b>
                </td>
            </tr>
            <tr style="border: none;">
                <td>账户余额：<b style="color: #EC303F;">@ViewBag.availableAmount</b> 元
                </td>
                <td>
                    <input onclick="window.parent.location.href = '/Account/Recharge'" class="btn-blue" type="button" value="充值" />
                </td>
            </tr>
            <tr style="display: none1;">
                <td colspan="3">积分减免：
                    <input id="useScore" type="checkbox" />使用积分
                    <input id="txtScore" style="width:80px;text-align:center;" disabled="disabled" type="text" Amount="@ViewBag.Amount"  value="@ViewBag.myScore" />(最低使用100积分)
                </td>
            </tr>
            <tr  style="display: none1;">
                <td colspan="3">可抵扣金额：<b class="score" style="color: #EC303F;">0</b>元(*温馨提示：大于1000的投资才能使用积分抵扣,且每次投资抵扣不能大于5000积分)
                </td>
            </tr>
            <tr  style="display: none;">
                <td colspan="2">
                    <input id="ckYes" type="checkbox" />我已阅读并同意全局金服<a target="_blank" href="http://www.changerbank.com/Article/NewsList?id=145">投资与咨询服务协议</a>
                </td>
            </tr>
            <tr style="border: none;">
                <td style="text-align: center">
                    <input id="btnSure" type="button"    cursor: default;" class="btn-blue" value="确定" />
                    <input id="btnCancle" onclick="window.parent.location.reload()" type="button" class="btn-blue" value="关闭" />
                </td>
            </tr>
        </table>
    </div>

    <form id="ConfirmForm" action="@Url.Action("ConfirmMiddlePage")" method="POST">
        <input type="hidden" name="issueBidNo" value="@Model.ProjectNo"/>
        <input type="hidden" name="submitBidNo" value="@submitBidNo"/>
        <input type="hidden" name="userName" id="sftuserName" value="@member.SFTUserName"/>
        <input type="hidden" name="creditAmount" id="sftcreditAmount" value="@ViewBag.Amount"/>
        <input type="hidden" name="score" id="sftscore" value=""/>
        <input type="hidden" name="projectId"  value="@Model.ID"/>
    </form>
</div>

<script type="text/javascript">
    function chongZhi() {
        window.location.href = "/Account/Recharge";
    }

    $(function () {
        $("#useScore").change(function () {
            if ($(this).is(":checked")) {
                var Amount = $("#txtScore").attr("Amount");
                $("#txtScore").removeAttr("disabled");
                $(".score").text(@discount);
                if (parseInt(@ViewBag.myScore) < 100) {
                    $(".score").text(0);
                }
            } else {
                $("#txtScore").attr("disabled", "disabled").val(@ViewBag.myScore);
                $(".score").text(0);
            }
        });

        $("#txtScore").keyup(function () {
            this.value = this.value.replace(/\D/g, ''); //限制输入数字
            var input = $(this).val();
            if (input != "" && parseInt(input) >= 100) {
                if (parseInt(@ViewBag.myScore) >= parseInt(input)) {//是否积分足够
                    if (parseInt(input) <= 5000) {//这里需要添加判断积分不能超过5000
                        $(".score").text((parseInt(input) * 0.01).toFixed(2));
                    } else {
                        $(".score").text(@discount);
                    $(this).val("@ViewBag.myScore");
                }
            } else {
                $(".score").text(@discount);
                    $(this).val("@ViewBag.myScore");
                    if (parseInt(@ViewBag.myScore) < 100) {
                        $(".score").text(0);
                    }
                }
            } else {
                $(".score").text(0);
            }
        });

        $("#btnSure").click(function () { //点击确定按钮的事件。
            //这里开始投标的逻辑代码
            if ($("#sftuserName").val() == null || $("#sftuserName").val() == "") {
                alert("请先开通盛付通账号");
                window.location.href = "/Account/AccountInfo";
                return;
            }
            var money = $("#sftcreditAmount").val();
            if (money != "") {//金额是否为空

                if (parseInt(money) <= parseInt(@avaAmounts)) {//是否超过可投金额

                    if (parseInt(money) >= parseInt(@Model.MinTenderAmount)) {//是否低于起投金额

                        if (parseInt(money) % parseInt(@Model.MinTenderAmount) == 0) {//是否是起投金额的整数倍

                            if (parseInt(money) <= parseInt(@ViewBag.availableAmount)) {//是否余额不足

                                //按照正常的逻辑把积分的数值传到后台
                                var score = 0;
                                if ($('#useScore').is(':checked')) {
                                    //这块积分需要到后台进入验证不然可以篡改,修改后把注释删除
                                    score = $("#txtScore").val();

                                }
                                //關閉自動投標
                                //将页面上选择的积分传到后台
                                if (score == 0) {
                                    $("#sftdiscountAmount").val("0.00");
                                } else {
                                    var _scoreAmount = (parseInt(score) * 0.01);
                                    var _sftcreditAmount = $("#sftcreditAmount").val();
                                    $("#sftdiscountAmount").val(_scoreAmount.toFixed(2));
                                }

                                //这里就是直接提交了
                                if ($("#useScore").is(":checked")) {
                                    $("#sftscore").val($("#txtScore").val());
                                }
                                $("#ConfirmForm").submit();

                            } else {

                                if ('@ViewBag.availableAmount' == "") {//是否session已超时
                                    location.href = '/Login/Index';
                                } else {
                                    $.dialog.confirm("对不起，您的账户余额不足，是否前去个人中心充值？", function () {
                                        location.href = "/Account/Recharge";
                                    });
                                }
                            }
                        } else {

                            $.dialog.tips("您好，请输入10的整数倍！", 1, 'tips.gif', function () {
                                window.parent.location.reload();
                            });
                        }
                    } else {

                        $.dialog.tips("您好，该标的起投金额为：" + parseInt(@Model.MinTenderAmount) + "元", 1, 'tips.gif', function () {
                            window.parent.location.reload();
                        });
                    }
                } else {
                    $.dialog.tips("您好，该标目前可投金额为：" + '@LY.Common.Utils.Tools.ConvertToMoney((long)avaAmounts, false)', 1, 'tips.gif', function () {
                        window.parent.location.reload();
                    });
                }
            } else {
                $.dialog.tips("您好，请输入投标金额！", 1, 'tips.gif', function () {
                    window.parent.location.reload();
                });
            }

        });
    });
</script>
